import UIKit
import PlaygroundSupport

PlaygroundPage.current.needsIndefiniteExecution = true

print("------------ operation ------------")
class ObjectOperation {
    func test () {
        // let thread = BlockOperation { [weak self] in
        //    self?.threadWorker()
        // }
        let thread = MyOperation()
        thread.completionBlock = { () -> Void in
            print("completionBlock")
        }
        let queue = OperationQueue()
        queue.addOperation(thread)
    }
    
    @objc func threadWorker() {
        sleep(1)
        print("threadWorker")
    }
}

class MyOperation: Operation {
    override func main () {
        sleep(1)
        print("in my MyOperation main!")
    }
}

let obj = ObjectOperation()
obj.test()
print("after invoke test")
